class Solution(object):
    def minimumTotal(self, triangle):
        if not triangle:
            return 0

        dp = triangle[-1][:]  # 从最后一层拷贝，防止修改原数组

        for i in range(len(triangle) - 2, -1, -1):
            for j in range(len(triangle[i])):
                dp[j] = triangle[i][j] + min(dp[j], dp[j + 1])

        return dp[0]
